; (function () {
    var timer,
        teacherlist = [];
        var  jiapshiZiGe=[];
        var AllClass1=[];
        
    var $gt = $('.tops');
    window.onscroll = function () {
        var osTop = document.documentElement.scrollTop;
        if (osTop > 500) {
            $gt.css({
                'display': 'block'
            })
        } else {
            $gt.css({
                "display": "none"
            })
        }
    }
    $('.tops').click(function () {
        timer = setInterval(function () {
            var osTop = document.documentElement.scrollTop;
            var speed = Math.floor(-osTop / 6);
            document.documentElement.scrollTop = document.body.scrollTop = osTop + speed;
            if (osTop == 0) {
                clearInterval(timer);
            }
        }, 10)
    })
    var getData = function () {
        var ajsx;
        if (window.XMLHttpRequest) {
            ajax = new XMLHttpRequest();
        } else {
            ajax = new ActiveXObject(Microsoft.XMLHttp);
        }
        ajax.open('get', 'http://192.168.0.149/tp5/public/index.php/index/teachers?pageCurrent=1&pageSize=5');
        ajax.send();
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
              
                renderList(JSON.parse(ajax.responseText).data.list);
            }
        }
    }
    var renderList = function (list) {
        var $ul = $('.teach_ul');
        var bStar = 0;
        var listarr = [];
        $.each(list, function (i, o) {
            listarr.push('<li class="teach_item fl">',
                '<div class="he_224">',
                '<img src="', o.img, '" alt="" class="teach_img">',
                '<p class="teach_name">', o.name, '</p>',
                '<span>',
                '<i class="dis_fl star_wp">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<p class="blackstar"></p>',
                '</i>',
                '</span>',
                '<span class="teach_fen">', o.veal, '分</span>',
                '</div>',
                '<div class="long_font_wp">',
                '<p class="teach_longfont">', o.desc, '</p>',
                '</div>',
                '</li>')
        })
        $ul.html(listarr.join(''));

        var $blackstar = $('.blackstar');
        $.each($blackstar, function (i, o) {
            var blWid = list[i].veal / 5 * 18 * 5;
            o.style.width = blWid + "px";
        })
    }

    var ArrAllClass = [];
    function init() {
        teacherLi();
        getLunTu();
        classall();
        getAllClass();
        getAllClass1();
        getData();

    }
    var getAllClass1 = function () {
        var ajax;
        if (window.XMLHttpRequest) {
            ajax = new XMLHttpRequest();
        } else {
            ajax = new ActiveXObject(Microsoft.XMLHttp);
        }
        ajax.open('get', 'http://192.168.0.149/tp5/public/index.php/index/classall?pageCurrent=1&pageSize=100&is_rem=1');
     
        ajax.send();
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
            
                AllClass1 = JSON.parse(ajax.responseText).data.list;
             
            }
        }
    }
    var getAllClass = function () {
        var ajax;
        if (window.XMLHttpRequest) {
            ajax = new XMLHttpRequest();
        } else {
            ajax = new ActiveXObject(Microsoft.XMLHttp);
        }
        ajax.open('get', 'http://192.168.0.149/tp5/public/index.php/index/classes?pageCurrent=1&pageSize=100');
     
        ajax.send();
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
               
                ArrAllClass = JSON.parse(ajax.responseText).data.list;
                getAllClassFenLei();
            }
        }
    }
    var getAllClassFenLei = function () {
        var ajax;
        if (window.XMLHttpRequest) {
            ajax = new XMLHttpRequest();
        } else {
            ajax = new ActiveXObject(Microsoft.XMLHttp);
        }
        ajax.open('get', 'http://192.168.0.149/tp5/public/index.php/index/classes/lists?pageCurrent=1&pageSize=100');
     
        ajax.send();
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
        
                var arrFenLei = JSON.parse(ajax.responseText).data.list;

                var firstArr = [], towArr = [], thressArr = [], fourArr = [], fiveArr = [];
                for (var i = 0; i < arrFenLei.length; i++) {
                    if (arrFenLei[i].pid == 2) {
                        firstArr.push(arrFenLei[i].title)
                        ArrAllClass[0].type = firstArr
                    } else if (arrFenLei[i].pid == 3) {
                        towArr.push(arrFenLei[i].title)
                        ArrAllClass[4].type = towArr
                    } else if (arrFenLei[i].pid == 4) {
                        thressArr.push(arrFenLei[i].title)
                        ArrAllClass[3].type = thressArr
                    } else if (arrFenLei[i].pid == 5) {
                        fourArr.push(arrFenLei[i].title)
                        ArrAllClass[1].type = fourArr
                    } else if (arrFenLei[i].pid == 6) {
                        fiveArr.push(arrFenLei[i].title)
                        ArrAllClass[2].type = fiveArr
                    }
                }
                /*  banner左侧*/
                // console.log(ArrAllClass)
                renderAllClass(ArrAllClass)
           
            }
        }
    }

   
  /* banner左侧 */
    function renderAllClass(d) {
        var arr = AllClass1;
        var AllClass = [];
        
        for (var w = 0; w < d.length; w++) {
            var arr1 = d[w].type
            console.log(arr1)
            AllClass.push(
                '<dd>',
                '<h3 class="clear">',
                '<span class="fl">' + d[w].title + '</span>',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/next.png" alt="" srcset="" class="fr article_i">',
                ' </h3>',
                ' <div class="article_displayNone">',
                '<div class="article_displayNone_content fl">',
                '<h4>欢迎选课！</h4>',
                '<div class="coursesName">',
                '<h5>',
                '<span class="coursesName_one">学科小类名称</span>',
                '</h5>',
                '<p class="coursesName_one_p">')
            for (var e = 0; e < arr1.length; e++) {
                AllClass.push(
                    '<span>' + arr1[e] + '</span>',
                    '<i>|</i>'
                )
            }
            AllClass.push(
                '</p>',
                '</div>',
                ' <div class="coursesName">',
                '<h5>推荐课程</h5>',
                '<p>',
                '<span>音体美面试课程讲解</span>',
                '</p>',
                '<p>',
                ' <span>' + arr[0].title + '</span>',
                '</p>',
                '<p>',
                '<span>综合素质（幼儿阶段）第二轮</span>',
                '</p>',
                '</div>',
                ' </div>',
                ' <ol class="fr article_displayNone_img">',
                '<li data-id="720960">',
                '<img src=' + arr[0].img + ' alt="">',
                '</li>',
                '<li data-id="523739">',
                '<img src="http://image.yunduoketang.com/course/42852/20190411/d0d615bd-454b-4a86-bac0-4dbe01733328.jpg" alt="">',
                ' </li>',
                ' <li data-id="523740">',
                '<img src="http://image.yunduoketang.com/course/42852/20190417/998ecd5a-8cb8-4c0a-81fd-31d138f838e1.jpg" alt="">',
                '</li>',
                ' </ol>',
                '</div>',
                '</dd>')
        }

        $('.bann_dl_dd').html(AllClass.join(''))
    }





    var getLunTu = function () {
        var ajax;
        if (window.XMLHttpRequest) {
            ajax = new XMLHttpRequest();
        } else {
            ajax = new ActiveXObject(Microsoft.XMLHttp);
        }
        ajax.open('get', 'http://192.168.0.149/tp5/public/index.php/index/banner?pageCurrent=1&pageSize=10');
      
        ajax.send();
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
                renderLunTu(JSON.parse(ajax.responseText).data.list);
            }
        }
    }


    var classall = function () {
        var ajax;
        if (window.XMLHttpRequest) {
            ajax = new XMLHttpRequest();
        } else {
            ajax = new ActiveXObject(Microsoft.XMLHttp);
        }
        ajax.open('get', 'http://192.168.0.149/tp5/public/index.php/index/classall?pageCurrent=1&pageSize=8');
        ajax.send();
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
                /* 推荐课程 */
                renderClassall(JSON.parse(ajax.responseText).data.list);
                // console.log(JSON.parse(ajax.responseText).data.list);
                /* 教师资格证 */
                jiapshiZiGe=JSON.parse(ajax.responseText).data.list;
                // localStorage.setItem('teacher', JSON.stringify(JSON.parse(ajax.responseText).data.list))
                renderteacher_fr(JSON.parse(ajax.responseText).data.list)
                teacherLi(jiapshiZiGe);
                // renderAllClass(jiapshiZiGe)
                
            }
        }
    }


    function renderClassall(b) {
        var ClassallArr = [];
        for (var i = 0; i < 4; i++) {
            ClassallArr.push(
                '<li data-p=',b[i].id,'>',
                '<div>',
                '<h4>',
                '<img src=' + b[i].img + ' alt="">',
                '</h4>',
                '<p>' + b[i].title + '</p>',
                ' </div>',
                '<div class="clear price">',
                '<span class="fl">',
                ' <i class="iconfontUser">',
                ' <img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/people.png" alt="" srcset="" class="people">',
                ' </i>' + b[i].people + '</span>',
                '<span class="fr ">',
                '<i>￥</i>' + b[i].price + '</span>',
                ' </div>',
                ' </li>'
            )
        }
        $('.TuiJianBox_fr').html(ClassallArr.join(''))
    }

    function renderteacher_fr(c) {
        // console.log(c);
        var teacher_frArr = [];
        for (var i = 0; i < c.length; i++) {
            teacher_frArr.push(
                '<li data-p=',c[i].id,'>',
                '<div>',
                '<h4>',
                '<img src=' + c[i].img + ' alt="">',
                ' </h4>',
                '  <p>' + c[i].title + '</p>',
                '</div>',
                '<div class="clear price">',
                '<span class="fl">',
                '<i class="iconfontUser">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/people.png" alt="" srcset="" class="people">',
                '</i>' + c[i].people + '</span>',
                '<span class="fr free">' + c[i].price_old + '</span>',
                '</div>',
                '</li>'
            )
        }
        $('.teacher_fr').html(teacher_frArr.join(''))
    }


    function renderLunTu(a) {
        var TuArr = [];
        for (var i = 0; i < a.length; i++) {
            TuArr.push('<img src=' + a[i].url + ' alt="" srcset=""  class="swiper-slide">')
        }
        $('.swiper-wrapper').html(TuArr.join(''))


        var mySwiper = new Swiper('.swiper-container', {
            loop: true, //设置为true，则开启loop（环路）模式，默认为false
            speed: 300,//滑动速度
            autoplay: 3000,//自动切换的时间间隔（单位ms），不设定该参数slide不会自动切换。
            autoplayDisableOnInteraction: false, //用户操作swiper之后，是否禁止autoplay，默认为true：停止。
            //--  如果需要分页器 --
            pagination: '.swiper-pagination',
            paginationClickable: true,
        })
        //--  如果需要前进后退按钮 --
        $('.arrow-left').click(function () {
            mySwiper.swipePrev();
        });
        $('.arrow-right').click(function () {
            mySwiper.swipeNext();
        });

    }



    function teacherLi() {
        $('.teacher_nav li').hover(function () {
            $(this).addClass('active').siblings().removeClass('active')
            // console.log($(this).index())
            // console.log( jiapshiZiGe)
            // var teacherShu = JSON.parse(localStorage.getItem('teacher'))
            // renderteacher_fr(teacherShu);
            renderteacher_fr(jiapshiZiGe);
        })
    }
    $('.packetLeft img').click(function () {
        console.log(this);
        // localhref();
    })
    $('.teacher_fr').on('click', 'li', function () {
        // console.log($(this).attr('data-p'));
        localhref($(this).attr('data-p'))
    })
    $('.TuiJianBox_fr').on('click', 'li', function () {
        // console.log($(this).attr('data-p'));
        localhref($(this).attr('data-p'))
    })
    // $('.TuiJianBox_lf').click(function () {
    //     // localhref()
    //     console.log(this);
    // })
    function localhref(ids) {
        location.href = 'eduXiang.html?id='+ids;
    }
    init();
})()
